package com.admin.business.background.venusOaDiscoloration;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: app致灰
 * @create: 2023-11-04 17:34:44
 **/
@Service("venusOaDiscolorationService")
@Slf4j
public class VenusOaDiscolorationService{

    @Resource
    VenusOaDiscolorationDao venusOaDiscolorationDao;

    /**
     * 添加app致灰,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - user_id:添加人
     *                   - name:名称
     *                   - scope_application:适用范围(1:助业门户网 2:助业网h5 3:助业网app 4:助业业主app 5:助业员工app)
     *                   - type:类型( 1:每年循环 2:临时)
     *                   - start_time:开始时间
     *                   - end_time:结束时间
     *                   - pause_resume:是否暂停( 1:正常 2:已暂停)
     *                   - pause_user_id:暂停人
     *                   - pause_time:暂停时间
     *                   - resume_user_id:恢复人
     *                   - resume_time:恢复时间
     *                   - begin_time:创建时间
     *                   - update_time:修改时间
     *                   - state:状态(0正常 1删除)
     * @return
     * @author Ht
     * @create: 2023-11-04 17:34:44
     */
    @OpenApi
    public Return addVenusOaDiscoloration(CDO cdoRequest) {
        venusOaDiscolorationDao.addVenusOaDiscoloration(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新app致灰数据
     *
     * @param cdoRequest - id:主键id
     *                   - user_id:添加人
     *                   - name:名称
     *                   - scope_application:适用范围(1:助业门户网 2:助业网h5 3:助业网app 4:助业业主app 5:助业员工app)
     *                   - type:类型( 1:每年循环 2:临时)
     *                   - start_time:开始时间
     *                   - end_time:结束时间
     *                   - pause_resume:是否暂停( 1:正常 2:已暂停)
     *                   - pause_user_id:暂停人
     *                   - pause_time:暂停时间
     *                   - resume_user_id:恢复人
     *                   - resume_time:恢复时间
     *                   - begin_time:创建时间
     *                   - update_time:修改时间
     *                   - state:状态(0正常 1删除)
     * @return
     * @author Ht
     * @create: 2023-11-04 17:34:44
     */
    @OpenApi
    public Return updateVenusOaDiscolorationById(CDO cdoRequest) {
        venusOaDiscolorationDao.updateVenusOaDiscolorationById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除app致灰数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-11-04 17:34:44
     */
    @OpenApi
    public Return deleteVenusOaDiscolorationById(CDO cdoRequest){
        int count = venusOaDiscolorationDao.deleteVenusOaDiscolorationById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除app致灰数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 17:34:44
     */
    @OpenApi
    public Return deleteVenusOaDiscoloration(CDO cdoRequest) {
        int count = venusOaDiscolorationDao.deleteVenusOaDiscoloration(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取app致灰数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-11-04 17:34:44
     */
    @OpenApi
    public Return getVenusOaDiscolorationById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaDiscolorationDao.getVenusOaDiscolorationById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取app致灰数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 17:34:44
     */
    @OpenApi
    public Return getVenusOaDiscolorationListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaDiscolorationDao.getVenusOaDiscolorationListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaDiscolorationDao.getVenusOaDiscolorationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取app致灰数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-11-04 17:34:44
     */
    @OpenApi
    public Return getVenusOaDiscolorationListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaDiscolorationDao.getVenusOaDiscolorationListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaDiscolorationDao.getVenusOaDiscolorationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
